﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Xk
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void dsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmDepartment f = frmDepartment.Instance();
            f.MdiParent = this;
            f.Show();
            f.Focus();
        }

        private void 班级信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmClass f = new frmClass();
            f.MdiParent = this;
            f.Show();
        }

        private void 学生信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmStudent f = new frmStudent();
            f.MdiParent = this;
            f.Show();
        }

        private void 课程信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmCourse f = new frmCourse();
            f.MdiParent = this;
            f.Show();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            if (CPublic.isManager)
            {
                LoginInfo.Text = "您好，" + CPublic.LoginInfo["UserName"] + "管理员，欢迎使用本系统！";
                学生选课ToolStripMenuItem.Enabled = false;
            }
            else
            {
                LoginInfo.Text = "您好，" + CPublic.LoginInfo["StuName"] + "同学，欢迎使用本系统！";
                dsToolStripMenuItem.Enabled = false;
                班级信息ToolStripMenuItem.Enabled = false;
                学生信息ToolStripMenuItem.Enabled = false;
                课程信息ToolStripMenuItem.Enabled = false;
                统计查询ToolStripMenuItem.Enabled = false;
                选课抽签结果ToolStripMenuItem.Enabled = false;
                lINQ示例ToolStripMenuItem.Enabled = false;
            }
        }

        private void toolStripStatusLabel1_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("mailto:237021692@qq.com");
        }

        private void 选课填报志愿ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmSelectCourse f = new frmSelectCourse();
            f.MdiParent = this;
            f.Show();
        }

        private void 我的报名结果ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmMyResult f = new frmMyResult();
            f.MdiParent = this;
            f.Show();
        }

        private void 随机抽签ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if(MessageBox.Show("确实要抽签么，将清除上次抽签结果？","确认",MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes)
            {
                SqlConnection cn = new SqlConnection(Properties.Settings.Default.XkConnectionString);
                SqlCommand cmd = new SqlCommand("EXEC ExecuteDrawLots", cn);

                try
                {
                    cn.Open();
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("执行成功！", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch
                {
                    MessageBox.Show("执行失败！", "消息", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    cn.Close();
                }
            }
        }

        private void 按课程察看抽签结果ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmChooseCourseResult f = new frmChooseCourseResult();
            f.MdiParent = this;
            f.Show();
        }

        private void 按班级性别统计学生人数ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmStudentNumGroupByClassSex f = new frmStudentNumGroupByClassSex();
            f.MdiParent = this;
            f.Show();
        }

        private void 未选课学生名单ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmStudentNotSelectCourse f = new frmStudentNotSelectCourse();
            f.MdiParent = this;
            f.Show();
        }

        private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmAboutBox f = new frmAboutBox();
            f.ShowDialog();
        }

        private void lINQTODataSet示例ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmStudentLinqToDataSet f = new frmStudentLinqToDataSet();
            f.MdiParent = this;
            f.Show();
        }

        private void lINQTOSQL示例ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmStudentLinqToSql f = new frmStudentLinqToSql();
            f.MdiParent = this;
            f.Show();
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            frmStudentLinqToObject f = new frmStudentLinqToObject();
            f.MdiParent = this;
            f.Show();
        }
    }
}
